package com.sky.controller.user;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    SetmealService setmealService;

    @Autowired
    DishService dishService;

    // 根据分类id查询套餐
    @Cacheable(cacheNames = "setmealCache", key = "'setmeal_'+#categoryId",
            unless = "#result.data==null || #result.data.size()<1")
    @GetMapping("/list")
    public Result getSetmealListByCategory(String categoryId) {
        List<Setmeal> setmeal = setmealService.getSetmealByCategoryId(categoryId);
        return Result.success(setmeal);
    }

    // 根据套餐id查询包含的菜品
    @GetMapping("/dish/{id}")
    public Result dishInSetmealById(@PathVariable String id) {

        List<DishItemVO> dishItemVOS = dishService.getSetmealDishByIds(id);
        return Result.success(dishItemVOS);
    }

}
